<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org" layout:decorate="~{layout}">
<head>
    <style type="text/css">
        table {
            border-collapse: collapse;
            margin: 0 auto;
            text-align: center;

        }

        table td, table th {
            width: 150px;
            border: 1px solid #cad9ea;
            color: #666;
            vertical-align: middle;
        }

        table thead th {
            background-color: #CCE8EB;
            width: 100px;
        }

        table tr:nth-child(odd) {
            background: #fff;
        }

        table tr:nth-child(even) {
            background: #F5FAFA;
        }
    </style>
    <style>
        * {
            margin: 0;
            padding: 0;
            font-family: Arial, helvetica, "Microsoft Yahei", sans-serif;;
            font-size: 16px;
        }

        body {
            overflow: hidden;
        / / 隐藏滚动条
        }

        h1 {
            color: #fff;
            font-size: 35px;
            font-weight: bold;
            margin: 80px auto 50px -25px;
            text-align: center;
            text-shadow: 0 1px 1px #555;
        }

        .box {
            width: 390px;
            height: 320px;

            border: solid 1px #ddd;
            border-radius: 5px;
            background: #FFF;
            position: absolute;
            left: 50%;
            top: 50%;
            margin-left: -195px;
            margin-top: -160px; /*注意处理浏览器圆角的兼容  */
            -webkit-box-shadow: 1px 1px 2px 0 rgba(0, 0, 0, .3);
            box-shadow: 1px 1px 2px 0 rgba(0, 0, 0, .3);
        }

        .box h2 {
            font-weight: normal;
            color: #666;
            font-size: 16px;
            line-height: 46px;
            height: 46px;
            overflow: hidden;
            text-align: center;
            border-bottom: solid 1px #ddd;
            background: #f7f7f7;
        }

        .input_box {
            width: 350px;
            padding-bottom: 15px;
            margin: 0 auto;
            overflow: hidden;
        }

        .input_box input {
            float: left;
            width: 348px;
            height: 40px;
            font-size: 14px;
            border: solid 1px #ddd;
            border-radius: 5px;
            text-indent: 10px;
            outline: none;
            line-height: 40px;
        }

        .input_box button{
            width:350px;
            height:48px;
            background:#008386;
            border:none;
            border-radius:5px;
            outline:none;
            cursor:pointer;
            font-size:16px;
            color:#FFF;
        }

        #error_box {
            height: 40px;
            width: 350px;
            margin: 0 auto;
            line-height: 40px;
            color: #fc4343;
        }
    </style>

    <style>
        body {
            font-size: 18px;
            line-height: 20px;
        }

        label {
            margin: 10px;
        }

        .a-radio {
            display: none;
        }

        .b-radio {
            display: inline-block;
            border: 1px solid #ccc;
            width: 16px;
            height: 16px;
            border-radius: 2px;
            vertical-align: middle;
            margin-right: 5px;
            position: relative;
        }

        .b-radio:before {
            content: '';
            font-size: 0;
            width: 10px;
            height: 10px;
            background: rgb(143, 188, 238);
            position: absolute;
            left: 50%;
            top: 50%;
            margin-left: -5px;
            margin-top: -5px;
            border-radius: 2px;
            display: none;
        }

        .a-radio:checked ~ .b-radio:before {
            display: block;
        }
    </style>
</head>

<body>
<div layout:fragment="content" th:remove="tag">
    <div id="app">
        <div class="row">
            <div class="col-xs-12">
                <div style="margin-bottom: 10px;">
                        <button  button type="button" class="btn btn-primary" id="cid"onclick="openTransferModal(this)">
                            星辰币
                        </button>
                        <button  button type="button" class="btn btn-primary" id="cid1"onclick="openTransferModal1(this)">
                            代币
                        </button>
                </div>
            </div>
        </div>
        <table align='center' border='1' cellspacing='0' width="90%" class="table">
            <tr>
                <td>time</td>
                <td>log</td>
            </tr>
            <tr th:each="log:${page.list}">
                <td th:text="${log.time}">null</td>
                <td th:text="${log.log}">null</td>
            </tr>
        </table>
        <br/>
        <div style="text-align:center">
            <a th:href="'http://111.231.107.131:8081'+@{/manage(start=0)}">[首 页]</a>
            <a th:href="'http://111.231.107.131:8081'+@{/manage(start=${page.pageNum-1})}">[上一页]</a>
            <a th:href="'http://111.231.107.131:8081'+@{/manage(start=${page.pageNum+1})}">[下一页]</a>
            <a th:href="'http://111.231.107.131:8081'+@{/manage(start=${page.pages})}">[末 页]</a>
        </div>
        <!--<script th:inline="javascript">-->

            <!--// 查询成功后向模态框插入数据并开启模态框。data是返回的JSON对象-->
            <!--function openAddModal(Obj) {-->
                <!--$("#myModalAdd").modal('show');-->
                <!--//获取点击行的某一列的值-->
                <!--//var stuno = document.getElementById("table").rows[2].cells[0].innerText;-->
                <!--//alert(stuno);-->
                <!--//获取当前点击行的id-->
                <!--var $td = $(Obj).parents('tr').children('td');-->
                <!--var gameId = $td.eq(0).text();-->
                <!--var homeTeam = $td.eq(1).text();-->
                <!--var homeTeamOdds = $td.eq(2).text();-->
                <!--var awayTeam = $td.eq(3).text();-->
                <!--var awayTeamOdds = $td.eq(4).text();-->
                <!--var money = $td.eq(5).text();-->
                <!--var username = [[${(#session.getAttribute('user')).username}]];-->
                <!--var earn = [[${(#session.getAttribute('user')).money}]];-->
                <!--$("#gameId").val(gameId);-->
                <!--$("#homeTeam").val(homeTeam);-->
                <!--$("#homeTeamOdds").val(homeTeamOdds);-->
                <!--$("#awayTeam").val(awayTeam);-->
                <!--$("#awayTeamOdds").val(awayTeamOdds);-->
                <!--$("#money").val(money);-->
                <!--$("#username").val(username);-->
                <!--$("#earn").val(earn);-->
                <!--// 显示模态框-->
            <!--};-->

        <!--</script>-->
    </div>
    <div class="modal fade" id="myModalTransfer" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
         aria-hidden="true">
        <div class="modal-dialog" style="width: auto">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"
                            aria-hidden="true">×
                    </button>
                    <h4 class="modal-title" id="myModalLabel">
                        余额:<div id="balance"></div><br/>
                        钱包地址：<div id="address"></div>
                    </h4>
                </div>
                <div class="modal-body">
                    <div class="input_box">
                        用户名:<input type="text" placeholder="用户名" id="username" name="username" readonly="readonly"/><br/>
                    </div>
                    <div class="input_box">
                        目标地址:<input type="text" placeholder="目标账户:" id="addressTo" name="addressTo" /><br/>
                    </div>
                    <div class="input_box">
                        金额:<input type="text" placeholder="金额:" id="pay" name="pay"/><br/>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default"
                            data-dismiss="modal">关闭
                    </button>
                    <button type="button" class="btn btn-primary" id="transfer">
                        转账
                    </button>
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
    </div><!-- /.modal -->
    <script>
        $(function () {
            $("#transfer").click(function () {
// 处理表单验证和交给后台处理的逻辑
                var oError = document.getElementById("error_box");
                var address= $("#addressTo").val();
                var username = $("#username").val();
                var pay = $("#pay").val();
                var isNotError = true;
                if (addressTo == "") {
                    oError.innerHTML = "目标地址为空 ";
                    isNotError = false;
                    $("#addressTo").focus();
                    return;
                }
                if (username == "") {
                    oError.innerHTML = "账号为空 ";
                    isNotError = false;
                    $("#username").focus();
                    return;
                }
                if (pay == "") {
                    oError.innerHTML = "转账金额为空 ";
                    isNotError = false;
                    $("#pay").focus();
                    return;
                }
                if (parseFloat(pay)>parseFloat((document.getElementById('balance').innerHTML).toString())||parseFloat(pay)<=0.001){
                    $.messager.alert("提示", '余额不足或下注金额错误');
                    return;
                }
                $.ajax({
                    type: "POST",
                    url:  "/manage/transfer",
                    dataType: "json",
                    contentType: "application/json",
                    data: JSON.stringify({
                        address:address,
                        username: username,
                        pay: pay,
                    }),
                    success: function (data) {
                        switch (data.result.toString()) {
                            case "1": {
                                $(".modal").css("display", "none");
                                $(".modal-backdrop").css("display", "none");
                                $.messager.alert("提示", '转账成功');
                                break;
                            }
                                ;
                            case "2": {
                                $.messager.alert("提示", '余额不足或转账金额错误');
                                break;
                            }
                            default: {
                                $.messager.alert("提示", '转账失败');
                                break;
                            }

                        }
                    }
                });

            });
        });
    </script>
    <script th:inline="javascript">

        function openTransferModal(Obj) {
            $("#myModalTransfer").modal('show');
            var username=[[${(#session.getAttribute('user')).username}]];
            $("#username").val(username);
            if (username == "") {
                oError.innerHTML = "账号为空 ";
                isNotError = false;
                $("#username").focus();
                return;
            }
            $.ajax({
                type: "POST",
                url: "/manage/reflashMoney",
                dataType: "json",
                contentType: "application/json",
                data: JSON.stringify({
                    username: username
                }),
                success: function (data) {
                    switch (data.result.toString()) {
                        case "1": {
                            $("#balance").text(data.balance.toString());
                            $("#address").text(data.address.toString());
                            break;
                        }
                            ;
                        case "2": {
                            $.messager.alert("提示", '余额不足或下注金额错误');
                            break;
                        }
                        case "0": {
                            $.messager.alert("提示", '下注失败');
                            break;
                        }

                    }
                }
            });
            // 显示模态框
        };
    </script>
    <div class="modal fade" id="myModalTransfer1" tabindex="-1" role="dialog" aria-labelledby="myModalLabel1"
         aria-hidden="true">
        <div class="modal-dialog" style="width: auto">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"
                            aria-hidden="true">×
                    </button>
                    <h4 class="modal-title" id="myModalLabel1">
                        余额:<div id="balance1"></div><br/>
                        账户名称：<div th:text="${(#session.getAttribute('user')).mail}"></div>
                    </h4>
                </div>
                <div class="modal-body">
                    <div class="input_box">
                        目标账户:<input type="text" placeholder="目标账户:" id="addressTo1" name="addressTo1" /><br/>
                    </div>
                    <div class="input_box">
                        代币名称:<input type="text" placeholder="代币:" id="tokenName1" name="tokenName1"/><br/>
                    </div>
                    <div class="input_box">
                        金额:<input type="text" placeholder="金额:" id="pay1" name="pay1"/><br/>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default"
                            data-dismiss="modal">关闭
                    </button>
                    <button type="button" class="btn btn-primary" id="transfer1">
                        转账
                    </button>
                    <button type="button" class="btn btn-primary" id="createAccount1">
                        开户
                    </button>
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
    </div><!-- /.modal -->
    <script>
        $(function () {
            $("#transfer1").click(function () {
// 处理表单验证和交给后台处理的逻辑
                var oError = document.getElementById("error_box");
                var address= $("#addressTo1").val();
                var pay = $("#pay1").val();
                var tokenName=$("#tokenName1").val();
                var isNotError = true;
                if (address == "") {
                    oError.innerHTML = "目标地址为空 ";
                    isNotError = false;
                    $("#addressTo").focus();
                    return;
                }
                if (tokenName == "") {
                    oError.innerHTML = "账号为空 ";
                    isNotError = false;
                    $("#tokenName").focus();
                    return;
                }
                if (pay == "") {
                    oError.innerHTML = "转账金额为空 ";
                    isNotError = false;
                    $("#pay").focus();
                    return;
                }
                $.ajax({
                    type: "POST",
                    url:  "/fabric/transferToken",
                    dataType: "json",
                    contentType: "application/json",
                    data: JSON.stringify({
                        address:address,
                        tokenName: tokenName,
                        pay: pay,
                    }),
                    success: function (data) {
                        // switch (data.result.toString()) {
                        //     case "1": {
                        //         $(".modal").css("display", "none");
                        //         $(".modal-backdrop").css("display", "none");
                        //         $.messager.alert("提示", '转账成功');
                        //         break;
                        //     }
                        //         ;
                        //     case "2": {
                        //         $.messager.alert("提示", '余额不足或转账金额错误');
                        //         break;
                        //     }
                        //     default: {
                        //         $.messager.alert("提示", '转账失败');
                        //         break;
                        //     }
                        //
                        //
                        // }
                        var str = JSON.stringify(data.result);
                        alert(str);
                    }
                });

            })
            $("#createAccount1").click(function(){
// 处理表单验证和交给后台处理的逻辑
                var oError = document.getElementById("error_box");
                $.ajax({
                    type: "POST",
                    url:"/fabric/createAccount",
                    dataType: "json",
                    contentType:"application/json",
                    //data:dataString,
                    success:function(data){
                        var str = JSON.stringify(data.result);
                        alert(str);
                    }

                });

            });
        })
    </script>
    <script th:inline="javascript">

        function openTransferModal1(Obj) {
            $("#myModalTransfer1").modal('show');
            $.ajax({
                type: "POST",
                url: "/fabric/balanceAll",
                dataType: "json",
                contentType: "application/json",
                success:function(data){
                    $("#balance1").text(data.balance.toString());
                }
            });
            // 显示模态框
        };
    </script>

</div>

</body>
</html>